using System;
using System.Web.Services.Protocols;
using System.Net;

namespace LiveWebService.ManageDomain
{
	/// <summary>
	/// Extended SOAP protocol class that provides access to raw data related to the last SOAP request or response.
	/// Used as the base class for the ManageDomain2SoapProxy class.
	/// </summary>
	/// <copyright>Copyright (C) 2007 Microsoft Corporation.  All rights reserved.</copyright>
	/// <disclaimer>
	/// Samples have not been formally tested by Microsoft, and Microsoft makes no claims and implies no warrenties
	/// regarding the samples.  For more information, see the Terms Of Use.
	/// </disclaimer>
    [System.Web.Services.WebServiceBindingAttribute()]
	public class SoapHttpClientProtocolEx: SoapHttpClientProtocol
	{
		public event EventHandler<ModifyWebRequestEventArgs> ModifyWebRequest;

        //internal byte[] soapRequest;
        //internal string soapRequestXml;
        //internal byte[] soapResponse;
        //internal string soapResponseXml;
		private HttpWebResponse lastHttpResponse;

		/// <summary>
		/// 
		/// </summary>
		public SoapHttpClientProtocolEx(): base()
		{
			
		}
		
		/// <summary>
		/// 
		/// </summary>
        //public byte[] SoapRequest
        //{
        //    get
        //    {
        //        return this.soapRequest;
        //    }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //public string SoapRequestXml
        //{
        //    get
        //    {
        //        return this.soapRequestXml;
        //    }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //public byte[] SoapResponse
        //{
        //    get
        //    {
        //        return this.soapResponse;
        //    }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //public string SoapResponseXml
        //{
        //    get
        //    {
        //        return this.soapResponseXml;
        //    }
        //}

		/// <summary>
		/// 
		/// </summary>
		public HttpWebResponse LastHttpResponse
		{
			get
			{
				return this.lastHttpResponse;
			}
		}
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="uri"></param>
		/// <returns></returns>
		protected override System.Net.WebRequest GetWebRequest(Uri uri)
		{
			HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
			OnModifyWebRequest(webRequest);
			return webRequest;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		/// <returns></returns>
		protected override System.Net.WebResponse GetWebResponse(System.Net.WebRequest request)
		{
			this.lastHttpResponse = (HttpWebResponse)base.GetWebResponse (request);
			return this.lastHttpResponse;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="request"></param>
		protected void OnModifyWebRequest(HttpWebRequest webRequest)
		{
			if(this.ModifyWebRequest != null)
			{
				this.ModifyWebRequest(this, new ModifyWebRequestEventArgs(webRequest));
			}
		}
	}
}